package com.batata.continuing.web.ai;

import cn.hutool.core.collection.CollUtil;
import com.batata.continuing.config.moreNote.token.NotNeedToken;
import com.batata.continuing.pojo.base.ResultData;
import com.batata.continuing.utils.kimi.Message;
import com.batata.continuing.utils.kimi.RoleEnum;
import com.batata.continuing.utils.kimi.MoonshotAiUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "kimi相关调用")
@RestController
@RequestMapping("/kimi")
public class KimiController {

//    List<ChatCompletionMessage> historyMessages = new ArrayList<>();
//    @Autowired

    private static List<Message> historyMessages = new ArrayList<>();


    @NotNeedToken
    @ApiOperation("send消息")
    @PostMapping("/sendAndGetOne")
    public ResultData<?> sendAndGetOne(String message) {
        List<Message> messages = CollUtil.newArrayList(
                new Message(RoleEnum.system.name(), "你是kimi AI"),
                new Message(RoleEnum.user.name(), message)
        );
        String s = MoonshotAiUtils.chat1("moonshot-v1-8k", messages);
        return ResultData.success(s);
    }


    @NotNeedToken
    @ApiOperation("send消息")
    @PostMapping("/sendAndGetMore")
    public ResultData<?> sendAndGetMore(String message) {
        System.out.println("message = " + message);

        if (historyMessages.isEmpty()) {
            historyMessages.add(new Message(RoleEnum.system.name(), "你是kimi AI"));
        }
        historyMessages.add(new Message(RoleEnum.user.name(), message));

        String answer = MoonshotAiUtils.chatMore("moonshot-v1-8k", historyMessages);

        historyMessages.add(new Message("assistant", answer));

        Map<String,String> data = new HashMap<>();
        data.put("answer",answer);
        return ResultData.success(data);
    }


}
